/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package seso;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;
import java.awt.GradientPaint;

/**
 *
 * @author Administrator
 */
public class RPasswordField extends javax.swing.JPasswordField {

    private boolean focus_Gained;
    private final int arcWH = 6;

    public RPasswordField() {
        super();
        setOpaque(false);
        setMargin(new java.awt.Insets(1, 4, 1, 4));
        //setFont(new Font("Arial Unicode", Font.PLAIN, 12));

        addFocusListener(new java.awt.event.FocusAdapter() {

            public void focusGained(java.awt.event.FocusEvent evt) {
                focus_Gained = true;
                repaint();
            }

            public void focusLost(java.awt.event.FocusEvent evt) {
                focus_Gained = false;
                repaint();
            }
        });
    }

    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g;
        int width = getWidth();
        int height = getHeight();

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, width, height, arcWH, arcWH);
        g2d.setClip(rect);

        GradientPaint gp = new GradientPaint(0.0F, 0.0F, new Color(200, 200, 200), 0.0F, height / 2, new Color(255, 255, 255), false);
        g2d.setPaint(gp);
        g2d.fillRoundRect(4, 4, width - 8, height - 8, arcWH, arcWH);

        super.paintComponent(g);
    }

    @Override
    protected void paintBorder(java.awt.Graphics g) {
        RoundRectangle2D.Double rect;
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        int width = getWidth();
        int height = getHeight();

        g2d.setColor(new Color(0, 0, 0));
        rect = new RoundRectangle2D.Double(3, 3, width - 7, height - 7, arcWH, arcWH);
        g2d.draw(rect);

        if (focus_Gained) {
            g2d.setColor(new Color(136, 178, 96));
            rect = new RoundRectangle2D.Double(2, 2, width - 5, height - 5, arcWH, arcWH);
            g2d.draw(rect);

            g2d.setColor(new Color(196, 229, 154));
            rect = new RoundRectangle2D.Double(1, 1, width - 3, height - 3, arcWH, arcWH);
            g2d.draw(rect);

            g2d.setColor(new Color(196, 229, 154));
            rect = new RoundRectangle2D.Double(0, 0, width - 1, height - 1, arcWH, arcWH);
            g2d.draw(rect);
        }
    }
}
